{include file="public/layout" /}
<body class="bodystyle" style="min-width: auto;">
    <div class="on-off_panel">
        <div class="title">会员中心
            <span id="guide_web_users_switch"  {eq name="$userConfig.web_users_switch" value="0"}hidden {/eq}>
                <a href="javascript:void(0);" onclick="ajax_submit(this, 'web', 'web_users_switch',0);" data-lmenuid="Member_users_index">关闭<i class="fa fa-window-close-o" aria-hidden="true"></i></a>
                <a href="javascript:void(0);" onclick="tag_call('web_users_switch');" class="red">[标签调用]</a>
            </span>

        </div>
        <div class="on-off_content {eq name="$globalConfig.web_users_switch" value="0"}show-shade{/eq}" id="users_centre">
            <div class="on-off_shade ">
                <div class="on-off_shadeCon">
                    <span>目前还没有开启会员模块功能，<a href="javascript:void(0);" onclick="ajax_submit(this, 'web', 'web_users_switch',1);" data-lmenuid="Member_users_index">我要开启</a></span>
                </div>
            </div>
            <div class="on-off_btns">
                <form class="layui-form" action="">
                    <ul>
                        <li>
                            <div class="on-off_btn">
                                <div class="on-off_btn_l">
                                    <p>会员投稿：</p>
                                </div>
                                <div class="on-off_btn_r">
                                    <input type="checkbox" name="users[users_open_release]" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchTest"
                                           data-authortoken="{$is_eyou_authortoken}" data-is_online="{$is_online}" {eq name="$userConfig.users_open_release" value="1"}checked="" {/eq}
                                           data-type="users" data-name="users_open_release" data-lmenuid="Member_users_index" value="{$userConfig.users_open_release}">
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="on-off_btn">
                                <div class="on-off_btn_l">
                                    <p>会员升级：</p>
                                </div>
                                <div class="on-off_btn_r">
                                    <input type="checkbox" name="level[level_member_upgrade]" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchTest"
                                           data-authortoken="{$is_eyou_authortoken}" data-is_online="{$is_online}" {eq name="$userConfig.level_member_upgrade" value="1"}checked="" {/eq}
                                    data-type="level" data-name="level_member_upgrade" data-lmenuid="Member_users_index" value="{$userConfig.level_member_upgrade}">
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="on-off_btn">
                                <div class="on-off_btn_l">
                                    <p>商城中心：</p>
                                </div>
                                <div class="on-off_btn_r">
                                    <input type="checkbox" name="shop[shop_open]" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchTest"
                                           data-authortoken="{$is_eyou_authortoken}" data-is_online="{$is_online}" {eq name="$userConfig.shop_open" value="1"}checked="" {/eq}
                                    data-type="shop" data-name="shop_open" data-lmenuid="Shop_home" value="{$userConfig.shop_open}">
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="on-off_btn">
                                <div class="on-off_btn_l">
                                    <p>支付功能：</p>
                                </div>
                                <div class="on-off_btn_r">
                                    <input type="checkbox" name="pay[pay_open]" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchTest"
                                           data-authortoken="{$is_eyou_authortoken}" data-is_online="{$is_online}" {eq name="$userConfig.pay_open" value="1"}checked="" {/eq}
                                    data-type="pay" data-name="pay_open" data-lmenuid="Member_users_index" value="{$userConfig.pay_open}">

                                </div>
                            </div>
                        </li>
                    </ul>
                </form>
            </div>
            <div class="on-off_list">
                <ul>
                    <li><a href="javascript:void(0);" data-href="{:url('Member/users_index')}" data-leftmenu="Member_users_index" onclick="gourl2(this);"><span>会员列表</span></a></li>
                    <li><a href="javascript:void(0);" data-href="{:url('Member/users_config')}" data-leftmenu="Member_users_index" onclick="gourl2(this);"><span>功能配置</span></a></li>
                </ul>
            </div>
            <div id="guide_users_open_release" {eq name="$userConfig.users_open_release" value="0"}hidden {/eq}>
                <div class="son-tit">
                    <span>├ 会员投稿</span>
                </div>
                <div class="on-off_list">
                    <ul>
                        <li><a href="javascript:void(0);" data-href="{:url('UsersRelease/conf')}" data-leftmenu="Member_users_index" onclick="gourl2(this);"><span>功能配置</span></a></li>
                    </ul>
                </div>
            </div>
            <div id="guide_level_member_upgrade" {eq name="$userConfig.level_member_upgrade" value="0"}hidden {/eq}>
                <div class="son-tit">
                    <span>├ 会员升级</span>
                </div>
                <div class="on-off_list">
                    <ul>
                        <li><a href="javascript:void(0);" data-href="{:url('Level/index')}" data-leftmenu="Member_users_index" onclick="gourl2(this);"><span>会员产品分类</span></a></li>
                        <li><a href="javascript:void(0);" data-href="{:url('Level/upgrade_index')}" data-leftmenu="Member_users_index" onclick="gourl2(this);"><span>会员业务记录</span></a></li>
                    </ul>
                </div>
            </div>
            <div id="guide_shop_open" {eq name="$userConfig.shop_open" value="0"}hidden {/eq}>
                <div class="son-tit">
                    <span>├ 商城中心</span>
                    <a href="javascript:void(0);" onclick="tag_call('shop_open');" class="red">[标签调用]</a>
                </div>
                <div class="on-off_list">
                    <ul>
                        <li><a href="javascript:void(0);" data-href="{:url('Shop/index')}" data-leftmenu="Shop_home" onclick="gourl2(this);"><span>订单列表</span></a></li>
                        <li><a href="javascript:void(0);" data-href="{:url('Shop/conf')}" data-leftmenu="Shop_home" onclick="gourl2(this);"><span>功能配置</span></a></li>
                    </ul>
                </div>
            </div>
            <div id="guide_pay_open" {eq name="$userConfig.pay_open" value="0"}hidden {/eq}>
                <div class="son-tit">
                    <span>├ 支付功能</span>
                </div>
                <div class="on-off_list">
                    <ul>
                        <li><a href="javascript:void(0);" data-href="{:url('System/api_conf')}" data-leftmenu="Member_users_index" onclick="gourl2(this);"><span>接口配置</span></a></li>
                        <li><a href="javascript:void(0);" data-href="{:url('Member/money_index')}" data-leftmenu="Member_users_index" onclick="gourl2(this);"><span>充值列表</span></a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="on-off_panel">
        <div class="title">高级选项</div>
        <div class="on-off_content">
            <div class="on-off_btns">
                <form class="layui-form" action="">
                    <ul>
                        {eq name="weapp_switch" value="true"}
                        <li>
                            <div class="on-off_btn">
                                <div class="on-off_btn_l">
                                    <p>插件应用：</p>
                                </div>
                                <div class="on-off_btn_r">
                                    <input type="checkbox" name="web[web_weapp_switch]" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchWeapp"
                                           data-type="web" data-name="web_weapp_switch" data-lmenuid="Weapp_index" value="{$globalConfig.web_weapp_switch}"
                                           {eq name="$globalConfig.web_weapp_switch" value="1"}checked="" {/eq}>
                                </div>
                            </div>
                        </li>
                        {/eq}
                        <li>
                            <div class="on-off_btn">
                                <div class="on-off_btn_l">
                                    <p>多语言：</p>
                                </div>
                                <div class="on-off_btn_r">
                                    <input type="checkbox" name="web[web_language_switch]" lay-skin="switch" lay-text="开启|关闭" lay-filter="switchTest"
                                           data-type="web" data-name="web_language_switch" data-lmenuid="Language_index" value="{$globalConfig.web_language_switch}"
                                           {eq name="$globalConfig.web_language_switch" value="1"}checked="" {/eq}>
                                    <!--<p class="notic">开启之后，顶部菜单会显示多语言入口</p>-->
                                    <span id="guide_web_language_switch" style="{if condition='empty($globalConfig.web_language_switch)'} display: none;{/if}">
                                        &nbsp;<a href="{:url('Language/index')}">[多语言设置]</a>
                                        &nbsp;<a href="javascript:void(0);" onclick="tag_call('web_language_switch');" class="red">[标签调用]</a>
                                    </span>
                                </div>
                            </div>
                        </li>
                    </ul>
                </form>
            </div>
        </div>
    </div>
    <input type="hidden" name="is_themeusers_exist" id="is_themeusers_exist" value="{$is_themeusers_exist}">
    <input type="hidden" name="is_themeshop_exist" id="is_themeshop_exist" value="{$is_themeshop_exist}">
    <script>
        layui.use(['form'], function() {
            var form = layui.form,
                layer = layui.layer
            //监听指定开关
            form.on('switch(switchWeapp)', function(data) {
                if (this.checked) {
                    var name = $(this).attr('data-name');
                    $(this).val(1);
                    ajax_submit(this, 'web', name,1);
                } else {
                    var name = $(this).attr('data-name');
                    $(this).val(0);
                    ajax_submit(this, 'web', name,-1);
                }
            });
            form.on('switch(switchTest)', function(data) {
                if (this.checked) {
                    var name = $(this).attr('data-name');
                    var type = $(this).attr('data-type');
                    $(this).val(1);
                    ajax_submit(this, type, name,1);
                } else {
                    var name = $(this).attr('data-name');
                    var type = $(this).attr('data-type');
                    $(this).val(0);
                    ajax_submit(this,type, name,0);
                }
            });
        });
        // 提交表单
        function ajax_submit(obj, inc_type, name,value){
            var _parent = parent;
            var lmenuid = $(obj).attr('data-lmenuid');
            var url = "{:url('Index/switch_map', ['_ajax'=>1])}";
            var syn_open_users = false; // 是否同步开启会员中心
            // 验证
            switch (name)
            {
                case 'shop_open':
                case 'pay_open':
                case 'users_open_release':
                case 'level_member_upgrade':
                    if (-1 < $.inArray(name, ['shop_open','pay_open']))
                    {
                        if(false == check_shop_open())
                        {
                            return false;
                        }
                    } else if (-1 < $.inArray(name, ['users_open_release','level_member_upgrade']))
                    {
                        if(false == check_users_open_release())
                        {
                            return false;
                        }
                    }

                    break;
            }
            // 标签调用按钮的显示与隐藏
            if (1 == value) {
                $('#guide_'+name).show();
            } else {
                $('#guide_'+name).hide();
            }
            if ('web_users_switch' == name ){
                if (value == 1){
                    $("#users_centre").removeClass('show-shade');
                } else{
                    $("#users_centre").addClass('show-shade');
                }
            }

            if (1 == $('#is_themeusers_exist').val()) {
                $('#is_themeusers_exist').val(0)
                loadmsg = '初始化中';
            } else if (1 == $('#is_themeshop_exist').val()) {
                $('#is_themeshop_exist').val(0)
                loadmsg = '初始化中';
            } else {
                loadmsg = '正在处理';
            }
            parent_layer_loading(loadmsg);

            $.ajax({
                type: "POST",
                url: url,
                data: {inc_type:inc_type,name:name,value:value,lmenuid:lmenuid},
                dataType: 'json',
                success: function (res) {
                    if(res.code == 1){
                        // 第一次模板同步下载
                        if ('web_users_switch' == name && 1 == res.data.is_syn) { // 会员中心模板下载
                            syn_theme_users(value,lmenuid);
                            return false;
                        } else if ('shop_open' == name && 1 == res.data.is_syn) { // 订单中心模板下载
                            syn_theme_shop(value,lmenuid);
                            return false;
                        } else {
                            _parent.layer.closeAll();
                            // 根据不同场景进行页面加载的处理
                            _parent.layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                                if (1 == res.data.reload) {
                                    window.location.reload();
                                } else if (2 == res.data.reload) {
                                    top.window.location.reload();
                                }
                            });
                        }
                    }else{
                        if (1 == res.data.code) {
                            $('input[name="shop[shop_open]').removeAttr('checked');
                            $('input[name="shop[shop_open]').val(0);
                            $('input[name="shop[shop_open]').next().removeClass('layui-form-onswitch');
                            $('input[name="shop[shop_open]').next().html('<em>关闭</em><i></i>');
                            _parent.layer.closeAll();
                            _parent.layer.alert(res.msg, {btn: ['购买授权'], icon: 4, title:false}, function(){
                                _parent.layer.closeAll();
                                window.location.reload();
                                window.open('http://www.eyoucms.com/buy');
                            });
                        } else {
                            _parent.layer.closeAll();
                            _parent.layer.alert(res.msg, {icon: 2, title:false}, function(){
                                _parent.layer.closeAll();
                                window.location.reload();
                            });
                        }
                    }

                    // 控制顶部与左侧菜单的显示与隐藏
                    try{
                        if (1 == value) {
                            $('#'+lmenuid, window.parent.document).show();
                            if ('shop_open' == name) {
                                $('#Member_users_index', window.parent.document).show();
                            } else if ('web_users_switch' == name && 1 == $("input[name='shop[shop_open]']:checked").val()) {
                                $('#Shop_home', window.parent.document).show();
                            }
                        } else {
                            if (-1 < $.inArray(name, ['web_users_switch','web_language_switch','web_diyminipro_switch','shop_open','web_weapp_switch'])) {
                                $('#'+lmenuid, window.parent.document).hide();
                                if ('web_users_switch' == name) {
                                    $('#Shop_home', window.parent.document).hide();
                                }
                            }
                        }
                    }catch(e){}
                },
                error:function(e){
                    _parent.layer.closeAll();
                    _parent.layer.alert(e.responseText, {icon: 2, title:false}, function(){
                        _parent.layer.closeAll();
                        window.location.reload();
                    });
                }
            });
        }
        function tag_call(name)
        {
            $.ajax({
                type: "POST",
                url: "{:url('System/ajax_tag_call', ['_ajax'=>1])}",
                data: {name:name},
                dataType: 'json',
                success: function (res) {
                    if(res.code == 1){
                        //询问框
                        var confirm = layer.confirm(res.data.msg, {
                                title: false,
                                area: ['70%','80%'],
                                btn: ['关闭'] //按钮

                            }, function(){
                                layer.close(confirm);
                            }
                        );
                    }else{
                        layer.alert(res.msg, {icon: 2, title:false});
                    }
                },
                error:function(e){
                    layer.alert(e.responseText, {icon: 2, title:false});
                }
            });
        }
        function gourl2(obj)
        {
            var leftmenu = $(obj).data('leftmenu');
            var href = $(obj).data('href');
            $('.eycms_cont_left .sub-menu a', window.parent.document).removeClass('on');
            $('#'+leftmenu, window.parent.document).addClass('on');
            window.location.href = href;
        }
        function check_users_open_release()
        {
            var obj = $('input[name="users[users_open_release]"]:checked');
            var is_online = $(obj).attr('data-is_online');
            if (1 == is_online) {
                var users_open_release = $(obj).val();
                if (1 == users_open_release && $(obj).attr('data-authortoken') == -1) {

                    $('input[name="users[users_open_release]"]').removeAttr('checked');
                    $('input[name="users[users_open_release]"]').val(0);
                    $('input[name="users[users_open_release]"]').next().removeClass('layui-form-onswitch');
                    $('input[name="users[users_open_release]"]').next().html('<em>关闭</em><i></i>');

                    var alert1 = layer.alert('会员投稿功能只限于授权域名！', {
                        icon: 4,
                        title:false,
                        btn: ['购买授权']
                    }, function(){
                        window.open('http://www.eyoucms.com/buy');
                        layer.close(alert1);
                    });
                    return false;
                }
            }
            return true;
        }
        function check_shop_open()
        {
            var obj = $('input[name="shop[shop_open]"]:checked');
            var is_online = $(obj).attr('data-is_online');
            if (1 == is_online) {
                var shop_open = $(obj).val();
                if (1 == shop_open && $(obj).attr('data-authortoken') == -1) {

                    $('input[name="shop[shop_open]').removeAttr('checked');
                    $('input[name="shop[shop_open]').val(0);
                    $('input[name="shop[shop_open]').next().removeClass('layui-form-onswitch');
                    $('input[name="shop[shop_open]').next().html('<em>关闭</em><i></i>');

                    var alert1 = layer.alert('订单功能只限于授权域名！', {
                        icon: 4,
                        title:false,
                        btn: ['购买授权']
                    }, function(){
                        window.open('http://www.eyoucms.com/buy');
                        layer.close(alert1);
                    });
                    return false;
                }
            }
            return true;
        }
        // 订单模板初始化下载
        function syn_theme_shop(value,lmenuid)
        {
            $.ajax({
                type : 'get',
                url : "{:url('Shop/ajax_syn_theme_shop', ['_ajax'=>1])}",
                data : {},
                dataType : 'json',
                success : function(res){
                    parent.layer.closeAll();
                    if(res.code == 1){
                        parent.layer.msg(res.msg, {icon: 1, time: 1000});
                    }else{
                        var icon = 2;
                        if (res.data.icon) {icon = res.data.icon;}
                        parent.layer.alert(res.msg, {icon: icon, title:false}, function(){
                            parent.layer.closeAll();
                            window.location.reload();
                        });
                    }
                    // 控制顶部与左侧菜单的显示与隐藏
                    try{
                        if (1 == value) {
                            $('#Member_users_index', window.parent.document).show();
                            $('#'+lmenuid, window.parent.document).show();
                        }
                    }catch(e){}
                },
                error: function(e){
                    parent.layer.closeAll();
                    parent.layer.alert(e.responseText, {icon: 2, title:false}, function(){
                        parent.layer.closeAll();
                        window.location.reload();
                    });
                }
            })
        }
        // 会员模板初始化下载
        function syn_theme_users(value,lmenuid)
        {
            $.ajax({
                type : 'get',
                url : "{:url('Member/ajax_syn_theme_users', ['_ajax'=>1])}",
                data : {},
                dataType : 'json',
                success : function(res){
                    parent.layer.closeAll();
                    if(res.code == 1){
                        parent.layer.msg(res.msg, {icon: 1, time: 1000});
                    }else{
                        parent.layer.alert(res.msg, {icon: 2, title:false}, function(){
                            parent.layer.closeAll();
                            window.location.reload();
                        });
                    }
                    // 控制顶部与左侧菜单的显示与隐藏
                    if (1 == value) {
                        $('#'+lmenuid, window.parent.document).show();
                    } else {
                        $('#'+lmenuid, window.parent.document).hide();
                    }
                },
                error: function(e){
                    parent.layer.closeAll();
                    parent.layer.alert(e.responseText, {icon: 2, title:false}, function(){
                        parent.layer.closeAll();
                        window.location.reload();
                    });
                }
            })
        }
    </script>
{include file="public/footer" /}
